#-*-coding:utf-8-*-
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.script import Manager
from sqlalchemy.sql import func  # func用来生成数据库函数代码

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://weixin_user:ncuhome1457854631@ncuhomev5.mysql.rds.aliyuncs.com/weixin'
app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
db = SQLAlchemy(app)


class Openid(db.Model):
    '''微信用户openid'''
    __tablename__ = 'openid'
    id = db.Column(db.Integer, primary_key=True)
    openid = db.Column(db.String(64), unique=True)
    time = db.Column(db.TIMESTAMP, server_default=func.now())


class Elec_Users(db.Model):
    """查电用户"""
    __tablename__ = "elec_users"
    id = db.Column(db.Integer, db.ForeignKey('openid.id'), primary_key=True)
    room_num = db.Column(db.String(16))
    contact_info = db.Column(db.String(32))
    contact_way = db.Column(db.String(8))
    time = db.Column(db.TIMESTAMP, server_default=func.now())


class Elec_Result(db.Model):
    '''查电查询结果'''
    __tablename__ = 'elec_result'
    id = db.Column(db.Integer, primary_key=True)
    room_num = db.Column(db.String(16))
    used_elec = db.Column(db.String(16))
    remaining_money = db.Column(db.String(16))
    remaining_elec = db.Column(db.String(16))
    remaining_time = db.Column(db.String(8))
    new_reading = db.Column(db.String(16))
    time = db.Column(db.TIMESTAMP, server_default=func.now())


class Elec_Informed(db.Model):
    '''已通知的查电用户'''
    __tablename__ = 'elec_informed'
    room_num = db.Column(db.String(16), primary_key=True)
    new_reading = db.Column(db.String(16))
    time = db.Column(db.TIMESTAMP, server_default=func.now())


class Cet_Users(db.Model):
    """CET用户"""
    __tablename__ = 'cet_users'
    id = db.Column(db.String(64), primary_key=True)
    examid = db.Column(db.String(32))
    name = db.Column(db.String(8), server_default="")
    time = db.Column(db.TIMESTAMP, server_default=func.now())
